<?php
/**
 * FORM表单控件
 * @author 梦幻开发组(huanran.zhao)
 * @since 2013-08-25
 * QQ : 523994553
 * site: http://www.draemfans.net
 */
class Widget {
	/**
	 * 单例:实例化
	 * @return widget
	 */
	public static function getInstance(){
		$widget = new Widget();
		return $widget;
	}

	/**
	 * checkbox
	 * @param serialize $params.data 控件值(序列化) <key=>value键值对>
	 * @param string $params.formParams 表单模型的配置参数
	 * @param string $params.name 控件名(另外还有$params.fullName和$params.is_params都会影响$params.name的值)
	 * @return html
	 */
	public static function checkbox($params=''){
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		$params['data'] = My::decodeJson($params['data']);
		$html = '';
		if(isset($params['formParams']['options']) AND is_array($params['formParams']['options'])){
			foreach($params['formParams']['options'] as $key=>$value){
				if(isset($params['data'][$key]) AND $key==$params['data'][$key])
					$checked="checked='checked'";
				else
					$checked="";
				$html .= '<label class="checkbox inline">'.$value."<input {$checked} name='{$params['name']}[{$key}]' type='checkbox' value='{$key}'/></label>　";
			}
		}
		return $html;
	}

	/**
	 * 自定义插件包
	 * @param string $params.formParams.file 插件名称
	 * @DEMO {{form type="package" data=$result.pack name="params[pack]" file="pack" item=$item}}
	 */
	public static function package($params=''){
		//print_r($params);exit;
		if(empty($params['file']))
			exit('请指定插件包文件file属性！');
		//引用插件文件
		include(PUB_DIR.'share/plug/package/'.$params['file'].'.php');
	}
	
	//autocomplete 自动完成
	public static function input_autocomplete($params=''){
		//解释params参数
		//$params = self::dealParams($params);
		return "<input name='{$params['name']}' type='text' value='{$params['value']}'/>";
	}
	//百度地图控件
	public static function input_map($params=''){
		//解释params参数
		$params = self::dealParams($params);
		//echo '<pre>';print_r($params);
		$default_point = My::arr2var($params,'formParams.point');//默认地图坐标
		$default_point = !empty($default_point)?$default_point:'113.30765,23.120049';//当值为空时,取指定坐标值
		$default_point = !empty($params['data'])?$params['data']:$default_point;//当值为空时,取默认值
		$default_level = My::arr2var($params,'formParams.level');//默认地图放大级别
		$default_level = !empty($default_level)?$default_level:'13';

		$url = Router::encodeUrl("index.php?app=baidu&act=insert&name={$params['name']}&default_point={$default_point}&default_level={$default_level}");
		$url = urldecode($url);
		return "<div class='input-append'><input class='span2 input-xlarge' value='{$params['data']}' name='{$params['name']}' type='text' value=''/><a class='iframe' title='编辑查看标注' width='840px' height='570px' href='{$url}'><button class='btn' type='button'><i class='icon-map-marker'></i>地图</button></a></div>";
	}
	//日期控件
	public static function input_date($params=''){
		//解释params参数
		$params = self::dealParams($params);
		$kind = isset($params['formParams']['kind'])?$params['formParams']['kind']:'date';
		$html = "<input class='input-xlarge Wdate {$kind}' name='{$params['name']}' type='text' value='{$params['data']}'/>";
		return $html;
	}
	//颜色选取控件
	public static function input_color($params=''){
		//解释params参数
		$params = self::dealParams($params);
		$format = isset($params['formParams']['format'])?"data-format='{$params['formParams']['format']}'":"data-format='hex'";
		$html = "<div class='input-append color'  {$format}>
					<input class='input-xlarge span2' id='appendedInput' name='{$params['name']}' type='text' value='{$params['data']}'/>
					<span class='add-on'></span>
				 </div>";
		return $html;
	}
	//自定义html代码
	public static function html($params=''){
		//解释params参数
		$params = self::dealParams($params);
		return isset($params['formParams']['html'])?$params['formParams']['html']:'';
	}

	/**
	 * checkbox
	 * @param serialize $params.data 控件值(序列化) <key=>value键值对>
	 * @param string $params.formParams 表单模型的配置参数
	 * @param string $params.name 控件名(另外还有$params.fullName和$params.is_params都会影响$params.name的值)
	 * @return html
	 */
	public static function select_fun($params=''){
		//解释params参数
		$params = self::dealParams($params);

		$select_fun = My::arr2var($params,'formParams.select_fun');
		//var_dump($select_fun);
		$select_fun = htmlspecialchars_decode($select_fun, ENT_QUOTES);
		@eval('$option='.$select_fun);
		//print_r($data);
		//是否multiple
		if(!empty($params['formParams']['is_multiple'])){
			$multiple = "multiple='multiple'";
			$name = $params['name'].'[]';
			$data = My::decodeJson($params['data']);
		}else{
			$multiple = '';
			$name = $params['name'];
		}
		//宽度
		$width = !empty($params['formParams']['width'])?'width:'.$params['formParams']['width']:'';
		//是否chosen
		$is_chosen = !empty($params['formParams']['is_chosen'])?"chosen":'';
		//placeholder
		$chosen_placeholder = ($is_chosen AND $multiple)?"data-placeholder='".(!empty($params['formParams']['placeholder'])?$params['formParams']['placeholder']:'请选择...')."'":'';
		$default_placeholder = (!$multiple AND !empty($params['formParams']['placeholder']))?'<option value="">'.(!empty($params['formParams']['placeholder'])?$params['formParams']['placeholder']:'<option value="">请选择...</option>').'</option>':'';
		//html
		$html = "<select class='{$is_chosen}' {$chosen_placeholder} {$multiple} name='{$name}' style='{$width}'>";
		$html .= $default_placeholder;
		if(isset($option) AND is_array($option))
		foreach($option as $key=>$value){
			if(!empty($params['formParams']['is_multiple']) AND in_array($key,$data)){//multiple多选
				$selected="selected='selected'";
			}elseif($key==$params['data'])//单选
				$selected="selected='selected'";
			else
				$selected="";
			$html .= "<option {$selected} value='{$key}'>{$value}</option>";
		}
		$html .= '</select>';
		return $html;
	}

	public static function select_db($params=''){
		//解释params参数
		$params = self::dealParams($params);

		$db_table = My::arr2var($params,'formParams.select_db_table');
		$db_key = My::arr2var($params,'formParams.select_db_key');
		$db_value = My::arr2var($params,'formParams.select_db_value');
		$db_where = My::arr2var($params,'formParams.select_db_where','1');
		if(!$db_table OR !$db_key OR !$db_value) exit('数据表相关参数有误!');
		$result = DB('')->query("select ".($db_key?'`'.$db_key.'`,':'')."`{$db_value}` from `{$db_table}` where 1 AND {$db_where}");
		$result = My::arr2one($result,array($db_key,$db_value));
		$is_chosen = !empty($params['formParams']['is_chosen'])?"chosen":'';
		$html = "<select class='{$is_chosen}' name='{$params['name']}'>";
		$html .= "<option value=''>请选择...</option>";
		foreach($result as $key=>$value){
			if(!empty($multiple) AND is_array($data) AND in_array($key,$data))
				$selected="selected='selected'";	
			elseif($key==$params['data'])
				$selected="selected='selected'";
			else
				$selected="";
			$html .= "<option {$selected} value='{$key}'>{$value}</option>";
		}
		$html .= '</select>';
		return $html;
	}

	/**
	 * select
	 * @param serialize $params.data 控件值(序列化) <key=>value键值对>
	 * @param string $params.formParams 表单模型的配置参数
	 * @param string $params.name 控件名(另外还有$params.fullName和$params.is_params都会影响$params.name的值)
	 * @return html
	 */
	public static function select($params=''){
		//解释params参数
		$params = self::dealParams($params);
		$html = '';
		if(empty($params['formParams']['options']) AND isset($params['option']))
			$params['formParams']['options'] = $params['option'];
		if(isset($params['formParams']['options']) AND is_array($params['formParams']['options'])){
			//是否chosen
			$is_chosen = !empty($params['formParams']['is_chosen'])?"chosen":'';
			//是否multiple
			if(!empty($params['formParams']['is_multiple'])){
				$multiple = "multiple='multiple'";
				$name = $params['name'].'[]';
				$data = My::decodeJson($params['data']);
			}else{
				$multiple = '';
				$name = $params['name'];
			}
			//宽度
			$width = !empty($params['formParams']['width'])?'width:'.$params['formParams']['width']:'';
			//html
			$html = "<select class='{$is_chosen}' {$multiple} name='{$name}' style='{$width}'>";
			//placeholder
			$html.= isset($params['placeholder'])?"<option value=''>{$params['placeholder']}</option>":"";
			foreach($params['formParams']['options'] as $key=>$value){
				if(!empty($multiple) AND is_array($data) AND in_array($key,$data))
					$selected="selected='selected'";	
				elseif($key==$params['data'])
					$selected="selected='selected'";
				else
					$selected="";
				$html .= "<option {$selected} value='{$key}'>{$value}</option>";
			}
			$html .= '</select>';
		}
		return $html;
	}

	//API自定义HTML
	public static function html_api($params=''){
		//解释params参数
		$params = self::dealParams($params);
		$api = My::arr2var($result,'formParams.api');
		$api = htmlspecialchars_decode($api, ENT_QUOTES);
		@eval('$result='.$api);
		return $result;
	}

	/**
	 * radio
	 * @param serialize $params.data 控件值(序列化) <key=>value键值对>
	 * @param string $params.formParams 表单模型的配置参数
	 * @param string $params.name 控件名(另外还有$params.fullName和$params.is_params都会影响$params.name的值)
	 * @return html
	 */
	public static function radio($params=''){
		//解释params参数
		$params = self::dealParams($params);
		$html = '';
		if(isset($params['formParams']['options']) AND is_array($params['formParams']['options'])){
			foreach($params['formParams']['options'] as $value){
				if($params['data']=='' AND $html=='')//第一次循环,而且checked为空没有值时,选中第一个项
					$checked="checked='checked'";
				elseif($value['key']==$params['data'] AND $params['data']!='')
					$checked="checked='checked'";
				else
					$checked="";
				$html .= '<label class="radio inline">'.$value['value']."<input {$checked} name='{$params['name']}' type='radio' value='{$value['key']}'/></label>　";
			}
		}
		return $html;
	}

	public static function textarea_ueditor($params=''){
	    //解释params参数
	    $params = self::dealParams($params);
	    $html = "<textarea id='{$params['id']}' class='editor' style='width:770px;height:150px;' name='{$params['name']}'>".My::decodeHtml($params['data'])."</textarea>";
	    $html.= self::img(array('kind'=>'ueditor','class'=>$params['id'],'item'=>'config'));//插入图片按钮的参数class=ueditor控件ID
	    return $html;
	}
	
	public static function textarea_xheditor($params=''){
		//解释params参数
		$params = self::dealParams($params);
		$html = "<div class='xheditor_div'><textarea class='editor {$params['class']} {$params['name']}' style='width:770px;height:150px;' name='{$params['name']}'>".My::decodeHtml($params['data'])."</textarea></div>";
		$html.= self::img(array('kind'=>'xheditor','class'=>$params['name'],'item'=>'config'));//插入图片按钮的参数class=xheditor控件名称
		return $html;
	}

	public static function textarea($params=''){
		//解释params参数
		$params = self::dealParams($params);
		$maxlength = !empty($params['formParams']['maxlength'])?"maxlength='{$params['formParams']['maxlength']}'":'';//maxlength
		$width = !empty($params['formParams']['width'])?'width:'.$params['formParams']['width'].'px;':'width:432px;';//宽度
		$height = !empty($params['formParams']['height'])?'height:'.$params['formParams']['height'].'px;':'height:60px;';//高度
		$placeholder = !empty($params['formParams']['placeholder'])?"placeholder='{$params['formParams']['placeholder']}'":'';//placeholder
		//return
		return "<textarea name='{$params['name']}' {$maxlength} {$placeholder} style='{$width}{$height}'>{$params['data']}</textarea>";
	}

	/**
	 * 附件上传
	 * @param string $params[name] input框名称
	 * @param string $params[fullName] input框全名称(有fullName时不取name)
	 * @param string $params[src] 图片链接
	 * @param string $params[item] 相册唯一id名称
	 * @param int $params[cat_id] 相册id
	 * @param string $type $type='params'时控件名称为数组形式params[name]
	 * @return html
	 */
	public static function file($params){
		//相册弹窗尺寸
		$iframeWidth = '735px';
		$iframeHeight = '503px';
		//print_r($params);
		$type = My::arr2var($params,'type');
		//分类id/item
		$item = '';
		if(isset($params['item']))
			$item = 'item='.$params['item'];
		elseif(isset($params['cat_id']) AND My::is_id($params['cat_id']))
			$item = 'cat_id='.$params['cat_id'];//相册id
		else
			$item = 'item=file';
		//解释params参数
		$params = self::dealParams($params);
		//是否有限制后缀名
		$ext = isset($params['ext'])?'&ext='.My::encode($params['ext']):'';
		//文件最大尺寸
		$maxsize = isset($params['maxsize'])?'&maxsize='.My::encode($params['maxsize']):'';
		$URL = Router::encodeUrl("index.php?app=photo&act=insert_file&type=input&name={$params['name']}&{$item}{$ext}{$maxsize}");
		$URL = urldecode($URL);
		$html  = "<div class='input-append valign'>
					<input class='span2 {$params['class']}' name='{$params['name']}' id='appendedInputButton' type='text' value='{$params['data']}'/>
					<a class='iframe' title='选择文件' width='{$iframeWidth}' height='{$iframeHeight}' href='{$URL}'><button class='btn' type='button'><i class='icon-folder-open'></i>选择文件</button></a>
					<a class='btn confirm ".(empty($params['data'])?'disabled':'')."' target='_blank' href='".(!empty($params['data'])?__PUB__.$params['data']:'javascript:')."' id='{$params['name']}_file' title='确定要下载吗?'><i class='icon-circle-arrow-down'></i>下载</a>
				  </div>";

		return $html;
	}

	/**
	 * (file[])附件上传
	 * @param string $params[name] 名称
	 * @param serialize $params[value] 序列化的值
	 * @param string $params[key] 值为$value[$key]
	 * @param string $params[type] $type='params'时控件名称为数组形式params[name]
	 * @return html
	 */
	public static function file_array($params){
		if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
		//相册弹窗尺寸
		$iframeWidth = '735px';
		$iframeHeight = '503px';
		//分类id/item
		$item = '';
		if(isset($params['item']))
			$item = 'item='.$params['item'];
		elseif(isset($params['cat_id']) AND My::is_id($params['cat_id']))
			$item = 'cat_id='.$params['cat_id'];//相册id
		else
			$item = 'item=file';
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		if(!is_array($params['data']))
			$params['data'] = My::decodeJson($params['data']);
		//限制最大行数
		$max_num = My::arr2var($params,'formParams.max_num');
		//input框标题
		$input_title = !empty($params['formParams']['input_title'])?$params['formParams']['input_title']:'标题';
		$input_width = !empty($params['formParams']['input_width'])?'width:'.$params['formParams']['input_width'].'px;':'width:150px;';
		$input_maxlength = !empty($params['formParams']['input_maxlength'])?'maxlength="'.$params['formParams']['input_maxlength'].'"':'';
		//图片框标题
		$img_title = !empty($params['formParams']['img_title'])?$params['formParams']['img_title']:'附件';
		$img_width = !empty($params['formParams']['img_width'])?'width:'.$params['formParams']['img_width'].'px;':'width:150px;';
		$img_maxlength = !empty($params['formParams']['img_maxlength'])?'maxlength="'.$params['formParams']['img_maxlength'].'"':'';
		//是否有限制后缀名
		$ext = isset($params['ext'])?'&ext='.My::encode($params['ext']):'';
		//文件最大尺寸
		$maxsize = isset($params['maxsize'])?'&maxsize='.My::encode($params['maxsize']):'';
		//print_r($params['data']);
		//json
		$params['data'] = is_array($params['data'])?array_values($params['data']):array();//重新排序数组//将数组的键值全部替换成数字0开头的数组
		$params['data'] = json_encode($params['data']);
		$theme = __PUB__.'share';
		$URL = Router::encodeUrl("index.php?app=photo&act=insert_file&type=input&id={$params['class']}<%=num%>&{$item}{$ext}{$maxsize}");
		$URL = urldecode($URL);
		$html= "<!--array_input S-->
				<div class='{$params['class']}'>
				  <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
				  <table class='change_table'>
					<thead>
						<tr class='thead'>
							<th>{$input_title}</th>
							<th>{$img_title}</th>
							<th style='width:65px;'><img src='{$theme}/images/gg_icon1.png' max_num='{$max_num}' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				  </table>
				</div>
				<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
				<script>
				$(function(){
					$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
				});
				//append出来的iframe标签,实时促发
				function iframe_live(){
					$('.iframe_live').colorbox({iframe:true,opacity:'0.3',width:'{$iframeWidth}', height:'{$iframeHeight}',href:$(this).attr('href'),fixed:true});
					return false;
				}
				</script>
				<script id='{$params['class']}_tr_html' type='text/html'>
					<tr lang='<%=num%>'>
						<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][title]' {$input_maxlength} style='{$input_width}' id='{$params['class']}<%=num%>_title' value='<%=result?result['title']:''%>'/> </td>
						<td class='textal'>
							<div class='input-append marginb0'>
								<input class='span2 {$params['class']}' name='{$params['name']}[<%=num%>][file]' id='{$params['class']}<%=num%>' type='text' value='<%=result?result['file']:''%>'/>
								<a onclick='iframe_live()' class='iframe_live' title='选择文件' width='{$iframeWidth}' height='{$iframeHeight}' href='{$URL}'><button class='btn' type='button'><i class='icon-folder-open'></i>选择文件</button></a>
								<a class='btn confirm <%=result && result['file']?'':'disabled'%>' target='_blank' href='<%=result && result['file']?'".__PUB__."'+result['file']:'javascript:'%>' id='{$params['name']}_file' title='确定要下载吗?'><i class='icon-circle-arrow-down'></i>下载</a>
							</div>
						</td>
						<td class='textac'> <img src='{$theme}/images/gg_icon2.png' class='reduce'/> </td>
					</tr>
				</script>
				<!--array_input E-->";
		return $html;
	}

	/**
	 * 插入图片<(img)单个图片>
	 * @param string $params[name] input框名称
	 * @param string $params[fullName] input框全名称(有fullName时不取name)
	 * @param string $params[src] 图片链接
	 * @param string $params[item] 相册唯一id名称
	 * @param int $params[cat_id] 相册id
	 * @param string $type $type='params'时控件名称为数组形式params[name]
	 * @return html
	 */
	public static function img($params){
		//print_r($params);
		//相册弹窗尺寸
		$iframeWidth = '735px';
		$iframeHeight = '503px';
		$kind = isset($params['kind'])?$params['kind']:'';
		//选择相册id或item
		$photo_id = '';
		if(isset($params['item']))
			$photo_id = 'item='.$params['item'];
		elseif(isset($params['cat_id']) AND My::is_id($params['cat_id']))
			$photo_id = 'cat_id='.$params['cat_id'];//相册id
		else
			$photo_id = 'item=config';
		//额外参数(如:id=7&table=datas)
		$photo_limit = (My::arr2var($params,'photo_limit')!='')?'&'.My::arr2var($params,'photo_limit'):"";
		$subdir = (My::arr2var($params,'subdir')!='')?'&subdir='.My::arr2var($params,'subdir'):"";
		//解释params参数
		$params = self::dealParams($params);
		//ueditor编辑器:插入图片
		if($kind=='ueditor'){
		    $URL = Router::encodeUrl("index.php?app=photo&act=insert&type=ueditor&".($params['class']?"class={$params['class']}":"name={$params['name']}")."&{$photo_id}{$subdir}");
		    $URL = urldecode($URL);
		    $html = "<div style='margin:10px;'><a title='选择插入图片' width='{$iframeWidth}' height='{$iframeHeight}' class='iframe btn btn-small' href='{$URL}'><i class='icon-eye-open'></i>插入图片</a></div>";
		}
		//xheditor编辑器:插入图片
		else if($kind=='xheditor'){
			$URL = Router::encodeUrl("index.php?app=photo&act=insert&type=xheditor&".($params['class']?"class={$params['class']}":"name={$params['name']}")."&{$photo_id}{$subdir}");
			$URL = urldecode($URL);
			$html = "<div style='margin:10px;'><a title='选择插入图片' width='{$iframeWidth}' height='{$iframeHeight}' class='iframe btn btn-small' href='{$URL}'><i class='icon-eye-open'></i>插入图片</a></div>";
		}
		//input插入图片
		else{
			$URL = Router::encodeUrl("index.php?app=photo&act=insert&type=input&id={$params['class']}&{$photo_id}{$photo_limit}{$subdir}");
			$URL = urldecode($URL);
			$html  = "<div class='input-append valign marginb0'><input class='span2 {$params['class']} onchange2show' name='{$params['name']}' id='{$params['class']}' type='text' value='{$params['data']}'/><a class='iframe' title='选择插入图片' width='{$iframeWidth}' height='{$iframeHeight}' href='{$URL}'><button class='btn' type='button'><i class='icon-eye-open'></i>浏览</button></a></div> ";
			$html .= "<img class='zoom valign' src='".My::thums($params['data'])."' id='{$params['class']}_img' style='max-width:60px;max-height:30px;_height:30px;_width:60px;'/>";
		}
		return $html;
	}

	/**
	 * (img[])动态图片
	 * @param string $params[name] 名称
	 * @param serialize $params[value] 序列化的值
	 * @param string $params[key] 值为$value[$key]
	 * @param string $params[type] $type='params'时控件名称为数组形式params[name]
	 * @return html
	 */
	public static function img_array($params){
		if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
		//相册弹窗尺寸
		$iframeWidth = '735px';
		$iframeHeight = '503px';
		//选择相册id或item
		if(isset($params['item']))
			$photo_id = 'item='.$params['item'];//相册名称
		elseif(isset($params['cat_id']) AND My::is_id($params['cat_id']))
			$photo_id = 'cat_id='.$params['cat_id'];//相册id
		else
			$photo_id = 'item=config';//默认相册(系统设置)
		$PUB = __PUB__;
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		if(!is_array($params['data']))
			$params['data'] = My::decodeJson($params['data']);
		//print_r($params['data']);
		//json
		$params['data'] = is_array($params['data'])?array_values($params['data']):array();//重新排序数组//将数组的键值全部替换成数字0开头的数组
		$params['data'] = json_encode($params['data']);
		//限制最大行数
		$max_num = My::arr2var($params,'formParams.max_num');
		//额外参数(如:id=7&table=datas)
		$photo_limit = (My::arr2var($params,'photo_limit')!='')?'&'.My::arr2var($params,'photo_limit'):"";
		//是否有指定value值中key
		//if(!empty($params['key']) AND is_array($arr[$params['key']])){
		//	$data = $data[$params['key']];
		//}
		$theme = __PUB__.'share';
		$URL = Router::encodeUrl("index.php?app=photo&act=insert&type=input&id={$params['class']}<%=num%>&{$photo_id}{$photo_limit}");
		$URL = urldecode($URL);
		$html= "<!--array_input S-->
				<div class='{$params['class']}'>
				  <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
				  <table class='change_table'>
					<thead>
						<tr class='thead'>
							<th style=''>图片</th>
							<th style='width:65px;'>预览</th>
							<th style='width:45px;'><img src='{$theme}/images/gg_icon1.png' max_num='{$max_num}' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				  </table>
				</div>
				<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
				<script>
				$(function(){
					$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
				});
				//append出来的iframe标签,实时促发
				function iframe_live(){
					$('.iframe_live').colorbox({iframe:true,opacity:'0.3',width:'{$iframeWidth}', height:'{$iframeHeight}',href:$(this).attr('href'),fixed:true});
					return false;
				}
				</script>
				<script id='{$params['class']}_tr_html' type='text/html'>
					<tr lang='<%=num%>'>
						<td class='textal'>
							<div class='input-append marginb0'>
								<input type='text' class='onchange2show' name='{$params['name']}[]' id='{$params['class']}<%=num%>' value='<%=result%>'/>
								<a onclick='iframe_live()' class='iframe_live btn' title='选择插入图片' href='{$URL}'><i class='icon-eye-open'></i>浏览</a>
							</div
						</td>
						<td class='textac'> <img class='zoom' src='<%=(result && result.slice(0,4)=='http')?result:(result?'{$PUB}'+result:'')%>' id='{$params['class']}<%=num%>_img' style='max-width:60px;max-height:30px;_height:30px;_width:60px;'/> </td>
						<td class='textac'> <img src='{$theme}/images/gg_icon2.png' class='reduce'/> </td>
					</tr>
				</script>
				<!--array_input E-->";
		return $html;
	}

	/**
	 * (img[])动态图片+单个input
	 * @param string $params[name] 名称
	 * @param serialize $params[value] 序列化的值
	 * @param string $params[key] 值为$value[$key]
	 * @param string $params[type] $type='params'时控件名称为数组形式params[name]
	 * @return html
	 */
	public static function img_array2($params){
		if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
		//相册弹窗尺寸
		$iframeWidth = '735px';
		$iframeHeight = '503px';
		//选择相册id或item
		if(isset($params['item']))
			$photo_id = 'item='.$params['item'];//相册名称
		elseif(isset($params['cat_id']) AND My::is_id($params['cat_id']))
			$photo_id = 'cat_id='.$params['cat_id'];//相册id
		else
			$photo_id = 'item=config';//默认相册(系统设置)
		$PUB = __PUB__;
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		if(!is_array($params['data']))
			$params['data'] = My::decodeJson($params['data']);
		//限制最大行数
		$max_num = My::arr2var($params,'formParams.max_num');
		//额外参数(如:id=7&table=datas)
		$photo_limit = (My::arr2var($params,'photo_limit')!='')?'&'.My::arr2var($params,'photo_limit'):"";
		//input框标题
		$input_title = !empty($params['formParams']['input_title'])?$params['formParams']['input_title']:'标题';
		$input_width = !empty($params['formParams']['input_width'])?'width:'.$params['formParams']['input_width'].'px;':'width:150px;';
		$input_maxlength = !empty($params['formParams']['input_maxlength'])?'maxlength="'.$params['formParams']['input_maxlength'].'"':'';
		//图片框标题
		$img_title = !empty($params['formParams']['img_title'])?$params['formParams']['img_title']:'图片';
		$img_width = !empty($params['formParams']['img_width'])?'width:'.$params['formParams']['img_width'].'px;':'width:150px;';
		$img_maxlength = !empty($params['formParams']['img_maxlength'])?'maxlength="'.$params['formParams']['img_maxlength'].'"':'';
		//print_r($params['data']);
		//json
		$params['data'] = is_array($params['data'])?array_values($params['data']):array();//重新排序数组//将数组的键值全部替换成数字0开头的数组
		$params['data'] = json_encode($params['data']);
		$theme = __PUB__.'share';
		//url
		$URL = Router::encodeUrl("index.php?app=photo&act=insert&type=input&id={$params['class']}<%=num%>_image&{$photo_id}{$photo_limit}");
		$URL = urldecode($URL);
		//html
		$html= "<!--array_input S-->
				<div class='{$params['class']}'>
				  <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
				  <table class='change_table'>
					<thead>
						<tr class='thead'>
							<th>{$input_title}</th>
							<th>{$img_title}</th>
							<th style='width:65px;'><img src='{$theme}/images/gg_icon1.png' max_num='{$max_num}' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				  </table>
				</div>
				<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
				<script>
				$(function(){
					$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
				});
				//append出来的iframe标签,实时促发
				function iframe_live(){
					$('.iframe_live').colorbox({iframe:true,opacity:'0.3',width:'{$iframeWidth}', height:'{$iframeHeight}',href:$(this).attr('href'),fixed:true});
					return false;
				}
				</script>
				<script id='{$params['class']}_tr_html' type='text/html'>
					<tr lang='<%=num%>'>
						<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][title]' {$input_maxlength} style='{$input_width}' id='{$params['class']}<%=num%>_title' value='<%=result?result['title']:''%>'/> </td>
						<td class='textal'>
							<div class='input-append marginb0'>
								<input type='text' class='onchange2show' name='{$params['name']}[<%=num%>][image]' {$img_maxlength} style='{$img_width}' id='{$params['class']}<%=num%>_image' value='<%=result?result['image']:''%>'/>
								<a onclick='iframe_live()' class='iframe_live btn' title='选择插入图片' href='{$URL}'><i class='icon-eye-open'></i>浏览</a>
							</div>
							<div style='width:60px;text-align:center;float:right;margin-left:6px;'>
								<img class='zoom' src='<%=result?(result['image'].slice(0,4)=='http'?result['image']:'{$PUB}'+result['image']):''%>' id='{$params['class']}<%=num%>_image_img' style='max-width:60px;max-height:30px;_height:30px;_width:60px;'/>
							</div>
						</td>
						<td class='textac'> <img src='{$theme}/images/gg_icon2.png' class='reduce'/> </td>
					</tr>
				</script>
				<!--array_input E-->";
		return $html;
	}

	/**
	 * (img[])动态图片+两个input
	 * @param string $params[name] 名称
	 * @param serialize $params[value] 序列化的值
	 * @param string $params[key] 值为$value[$key]
	 * @param string $params[type] $type='params'时控件名称为数组形式params[name]
	 * @return html
	 */
	public static function img_array3($params){
		if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
		//相册弹窗尺寸
		$iframeWidth = '735px';
		$iframeHeight = '503px';
		//选择相册id或item
		if(isset($params['item']))
			$photo_id = 'item='.$params['item'];//相册名称
		elseif(isset($params['cat_id']) AND My::is_id($params['cat_id']))
			$photo_id = 'cat_id='.$params['cat_id'];//相册id
		else
			$photo_id = 'item=config';//默认相册(系统设置)
		$PUB = __PUB__;
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		if(!is_array($params['data']))
			$params['data'] = My::decodeJson($params['data']);
		//限制最大行数
		$max_num = My::arr2var($params,'formParams.max_num');
		//额外参数(如:id=7&table=datas)
		$photo_limit = (My::arr2var($params,'photo_limit')!='')?'&'.My::arr2var($params,'photo_limit'):"";
		//input框标题1
		$input_title1 = !empty($params['formParams']['input_title1'])?$params['formParams']['input_title1']:'标题';
		$input_width1 = !empty($params['formParams']['input_width1'])?'width:'.$params['formParams']['input_width1'].'px;':'width:150px;';
		$input_maxlength1 = !empty($params['formParams']['input_maxlength1'])?'maxlength="'.$params['formParams']['input_maxlength1'].'"':'';
		//input框标题2
		$input_title2 = !empty($params['formParams']['input_title2'])?$params['formParams']['input_title2']:'链接';
		$input_width2 = !empty($params['formParams']['input_width2'])?'width:'.$params['formParams']['input_width2'].'px;':'width:140px;';
		$input_maxlength2 = !empty($params['formParams']['input_maxlength2'])?'maxlength="'.$params['formParams']['input_maxlength2'].'"':'';
		//图片框标题
		$img_title = !empty($params['formParams']['img_title'])?$params['formParams']['img_title']:'图片';
		$img_width = !empty($params['formParams']['img_width'])?'width:'.$params['formParams']['img_width'].'px;':'width:130px;';
		$img_maxlength = !empty($params['formParams']['img_maxlength'])?'maxlength="'.$params['formParams']['img_maxlength'].'"':'';
		//dump($params['data']);
		//json
		$params['data'] = is_array($params['data'])?array_values($params['data']):array();//重新排序数组//将数组的键值全部替换成数字0开头的数组
		$params['data'] = json_encode($params['data']);
		$theme = __PUB__.'share';
		//url
		$URL = Router::encodeUrl("index.php?app=photo&act=insert&type=input&id={$params['class']}<%=num%>_image&{$photo_id}{$photo_limit}");
		$URL = urldecode($URL);
		//html
		$html= "<!--array_input S-->
				<div class='{$params['class']}'>
				  <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
				  <table class='change_table'>
					<thead>
						<tr class='thead'>
							<th>{$input_title1}</th>
							<th>{$input_title2}</th>
							<th>{$img_title}</th>
							<th style='width:65px;'><img src='{$theme}/images/gg_icon1.png' max_num='{$max_num}' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				  </table>
				</div>
				<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
				<script>
				$(function(){
					$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
				});
				//append出来的iframe标签,实时促发
				function iframe_live(){
					$('.iframe_live').colorbox({iframe:true,opacity:'0.3',width:'{$iframeWidth}', height:'{$iframeHeight}',href:$(this).attr('href'),fixed:true});
					return false;
				}
				</script>
				<script id='{$params['class']}_tr_html' type='text/html'>
					<tr lang='<%=num%>'>
						<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][title1]' {$input_maxlength1} style='{$input_width1}' id='{$params['class']}<%=num%>_title' value='<%=result?result['title1']:''%>'/> </td>
						<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][title2]' {$input_maxlength2} style='{$input_width2}' id='{$params['class']}<%=num%>_title' value='<%=result?result['title2']:''%>'/> </td>
						<td class='textal'>
							<div class='input-append marginb0'>
								<input type='text' class='onchange2show' name='{$params['name']}[<%=num%>][image]' {$img_maxlength} style='{$img_width}' id='{$params['class']}<%=num%>_image' value='<%=result?result['image']:''%>'/>
								<a onclick='iframe_live()' class='iframe_live btn' title='选择插入图片' href='{$URL}'><i class='icon-eye-open'></i>浏览</a>
							</div>
							<div style='width:60px;text-align:center;float:right;margin-left:6px;'>
								<img class='zoom' src='<%=result?(result['image'].slice(0,4)=='http'?result['image']:'{$PUB}'+result['image']):''%>' id='{$params['class']}<%=num%>_image_img' style='max-width:60px;max-height:30px;_height:30px;_width:60px;'/>
							</div>
						</td>
						<td class='textac'> <img src='{$theme}/images/gg_icon2.png' class='reduce'/> </td>
					</tr>
				</script>
				<!--array_input E-->";
		return $html;
	}
	
	
	/**
	 * (img[])动态图片+三个input
	 * @param string $params[name] 名称
	 * @param serialize $params[value] 序列化的值
	 * @param string $params[key] 值为$value[$key]
	 * @param string $params[type] $type='params'时控件名称为数组形式params[name]
	 * @return html
	 */
	public static function img_array4($params){
	    if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
	    //相册弹窗尺寸
	    $iframeWidth = '735px';
	    $iframeHeight = '503px';
	    //选择相册id或item
	    if(isset($params['item']))
	        $photo_id = 'item='.$params['item'];//相册名称
	    elseif(isset($params['cat_id']) AND My::is_id($params['cat_id']))
	    $photo_id = 'cat_id='.$params['cat_id'];//相册id
	    else
	        $photo_id = 'item=config';//默认相册(系统设置)
	    $PUB = __PUB__;
	    //解释params参数
	    $params = self::dealParams($params);
	    //data解码
	    if(!is_array($params['data']))
	        $params['data'] = My::decodeJson($params['data']);
	    //限制最大行数
	    $max_num = My::arr2var($params,'formParams.max_num');
	    //额外参数(如:id=7&table=datas)
	    $photo_limit = (My::arr2var($params,'photo_limit')!='')?'&'.My::arr2var($params,'photo_limit'):"";
	    //input框标题1
	    $input_title1 = !empty($params['formParams']['input_title1'])?$params['formParams']['input_title1']:'标题';
	    $input_width1 = !empty($params['formParams']['input_width1'])?'width:'.$params['formParams']['input_width1'].'px;':'width:150px;';
	    $input_maxlength1 = !empty($params['formParams']['input_maxlength1'])?'maxlength="'.$params['formParams']['input_maxlength1'].'"':'';
	    //input框标题2
	    $input_title2 = !empty($params['formParams']['input_title2'])?$params['formParams']['input_title2']:'副标题';
	    $input_width2 = !empty($params['formParams']['input_width2'])?'width:'.$params['formParams']['input_width2'].'px;':'width:150px;';
	    $input_maxlength2 = !empty($params['formParams']['input_maxlength2'])?'maxlength="'.$params['formParams']['input_maxlength2'].'"':'';
	    //input框标题3
	    $input_title3 = !empty($params['formParams']['input_title3'])?$params['formParams']['input_title3']:'链接';
	    $input_width3 = !empty($params['formParams']['input_width3'])?'width:'.$params['formParams']['input_width3'].'px;':'width:140px;';
	    $input_maxlength3 = !empty($params['formParams']['input_maxlength3'])?'maxlength="'.$params['formParams']['input_maxlength3'].'"':'';
	    //图片框标题
	    $img_title = !empty($params['formParams']['img_title'])?$params['formParams']['img_title']:'图片';
	    $img_width = !empty($params['formParams']['img_width'])?'width:'.$params['formParams']['img_width'].'px;':'width:130px;';
	    $img_maxlength = !empty($params['formParams']['img_maxlength'])?'maxlength="'.$params['formParams']['img_maxlength'].'"':'';
	    //dump($params['data']);
	    //json
	    $params['data'] = is_array($params['data'])?array_values($params['data']):array();//重新排序数组//将数组的键值全部替换成数字0开头的数组
	    $params['data'] = json_encode($params['data']);
	    $theme = __PUB__.'share';
	    //url
	    $URL = Router::encodeUrl("index.php?app=photo&act=insert&type=input&id={$params['class']}<%=num%>_image&{$photo_id}{$photo_limit}");
		$URL = urldecode($URL);
	    //html
	    $html= "
	    <!--array_input S-->
	    <div class='{$params['class']}'>
	    <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
	    <table class='change_table'>
	    <thead>
	    <tr class='thead'>
		    <th>{$input_title1}</th>
		    <th>{$input_title2}</th>
		    <th>{$input_title3}</th>
		    <th>{$img_title}</th>
	        <th style='width:65px;'><img src='{$theme}/images/gg_icon1.png' max_num='{$max_num}' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
	    </tr>
	    </thead>
	    <tbody>
	    </tbody>
	    </table>
	    </div>
	    <script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
	    <script>
	        $(function(){
	        $('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
			});
			//append出来的iframe标签,实时促发
			function iframe_live(){
			$('.iframe_live').colorbox({iframe:true,opacity:'0.3',width:'{$iframeWidth}', height:'{$iframeHeight}',href:$(this).attr('href'),fixed:true});
			return false;
			}
		</script>
		<script id='{$params['class']}_tr_html' type='text/html'>
			<tr lang='<%=num%>'>
			<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][title1]' {$input_maxlength1} style='{$input_width1}' id='{$params['class']}<%=num%>_title' value='<%=result?result['title1']:''%>'/> </td>
			<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][title2]' {$input_maxlength2} style='{$input_width2}' id='{$params['class']}<%=num%>_title' value='<%=result?result['title2']:''%>'/> </td>
			<td class='textal'> <input type='text' name='{$params['name']}[<%=num%>][title3]' {$input_maxlength3} style='{$input_width3}' id='{$params['class']}<%=num%>_title' value='<%=result?result['title3']:''%>'/> </td>
			<td class='textal'>
			<div class='input-append marginb0'>
			<input type='text' class='onchange2show' name='{$params['name']}[<%=num%>][image]' {$img_maxlength} style='{$img_width}' id='{$params['class']}<%=num%>_image' value='<%=result?result['image']:''%>'/>
			<a onclick='iframe_live()' class='iframe_live btn' title='选择插入图片' href='{$URL}'><i class='icon-eye-open'></i>浏览</a>
			</div>
			<div style='width:60px;text-align:center;float:right;margin-left:6px;'>
				<img class='zoom' src='<%=result?(result['image'].slice(0,4)=='http'?result['image']:'{$PUB}'+result['image']):''%>' id='{$params['class']}<%=num%>_image_img' style='max-width:60px;max-height:30px;_height:30px;_width:60px;'/>
			</div>
			</td>
			<td class='textac'> <img src='{$theme}/images/gg_icon2.png' class='reduce'/> </td>
			</tr>
		</script>
		<!--array_input E-->";
		return $html;
	}

	/**
	 * 用于多维度复杂数据模型(X*X)
	 * @param string $params[name] input框名称
	 * @param serialize $params[options] 数组options值(key,value)
	 * @param string $params[type] $params[type]='params'时控件名称为数组形式params[name]
	 * @return html
	 */
	public static function more($params=''){
		if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		if(!is_array($params['data']))
			$params['data'] = My::decodeJson($params['data']);
		/*****特殊处理 S*****/
		//将非这种类型的数组转换(Array ( [1] => 1 [2] => 2 [3] => 3 ))
		if(is_array($params['data']) AND !isset($params['data']['key']) AND !isset($params['data']['value'])){
			foreach($params['data'] as $key=>$value){
				$temp['key'][] = $key;
				$temp['value'][] = $value;
			}
			$params['data'] = $temp;
		}
		/*****特殊处理 E*****/
		//json
		$params['data'] = json_encode($params['data']);
		//资源文件
		$theme = __PUB__.'share';
		dump($params['formParams']);

		$titles = $trs = '';
		if(isset($params['formParams']['options']['key']) AND is_array($params['formParams']['options']['key']))
		foreach($params['formParams']['options']['key'] as $key=>$value){
			$titles .= "<th style='width:50px;'>{$params['formParams']['options']['title'][$key]}</th>";
			$trs .= "<td class='textal'>".Form::form(array('type'=>$params['formParams']['options']['type'][$key],'data'=>isset($result['params']['options'])?$result['params']['options']:''))."</td>";
		}
		$html= "<!--array_input S-->
				<div class='{$params['class']}'>
				  <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
				  <table class='change_table'>
					<thead>
						<tr class='thead'>
							{$titles}
							<th style='width:40px;'><img src='{$theme}/images/gg_icon1.png' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				  </table>
				</div>
				<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
				<script>
					$(function(){
						$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
					});
				</script>
				<script id='{$params['class']}_tr_html' type='text/html'>
					<tr lang='<%=num%>'>
						{{$trs}}
						<td class='textac'><img src='{$theme}/images/gg_icon2.png' class='reduce'/></td>
					</tr>
				</script>
				<!--array_input E-->";
		return $html;
	}

	/**
	 * 私有函数,仅用于表单模型的"混合自定义""
	 * 注意: 这里的data统一格式为: Array ( [key] => Array ( [0] => 9 [1] => 1 [2] => 3 [3] => 5 [4] => 7 ) [value] => Array ( [0] => 11 [1] => 2 [2] => 4 [3] => 6 [4] => 8 ) )
	 * @return html
	 */
	public static function __more($params=''){
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		if(!is_array($params['data']))
			$params['data'] = My::decodeJson($params['data']);
		//dump($params['data']);
		//json
		$params['data'] = json_encode($params['data']);
		//资源文件
		$theme = __PUB__.'share';
		$html= "<!--array_input S-->
				<div class='{$params['class']}'>
				  <table class='change_table'>
					<thead>
						<tr class='thead'>
							<th style='width:50px;'>字段名</th>
							<th style='width:60px;'>标题</th>
							<th style='width:60px;'>控件类型</th>
							<th style='width:40px;'><img src='{$theme}/images/gg_icon1.png' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				  </table>
				</div>
				<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
				<script>
					$(function(){
						$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
					});
				</script>
				<script id='{$params['class']}_tr_html' type='text/html'>
					<tr lang='<%=num%>'>
					<td class='textal'> <input style='width:50px !important;' type='text' name='{$params['name']}[key][]' value='<%=result?result['key'][num]:''%>' placeholder='英文'/> </td>
					<td class='textal'> <input style='width:60px !important;' type='text' name='{$params['name']}[title][]' value='<%=result?result['title'][num]:''%>' placeholder='可以中文'/> </td>
					<td class='textal'> <input style='width:60px !important;' type='text' name='{$params['name']}[type][]' value='<%=result?result['type'][num]:''%>' placeholder='英文'/> </td>
					<td class='textac'><img src='{$theme}/images/gg_icon2.png' class='reduce'/></td>
					</tr>
				</script>
				<!--array_input E-->";
		return $html;
	}

	/**
	 * 用于两列的动态文本框
	 * @return html
	 */
	public static function input_array2($params=''){
		if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		if(!is_array($params['data']))
			$params['data'] = My::decodeJson($params['data']);
		/*****特殊处理(将来请废弃) S*****/
		if(is_array($params['data']) AND (isset($params['data']['key']) OR !is_array(current($params['data'])))){
			echo "<span class='red'>当您看到以下打印数据,请别紧张,因为此数据为旧数据结构,请点击保存数据即会消失!谢谢您的合作!</span><br>";
			dump($params['data']);//打印数据,提示用户这是旧数据结构,将其改正即可消失
			//key-value数据,自动纠正
			if(isset($params['data']['key']) AND is_array($params['data']['key'])){
				foreach($params['data']['key'] as $key=>$value){
					$temp[$key]['key'] = $value;
					$temp[$key]['value'] = $params['data']['value'][$key];
				}
				$params['data'] = $temp;
			}
		}
		/*****特殊处理(将来请废弃) E*****/
		//json
		$params['data'] = is_array($params['data'])?array_values($params['data']):array();//重新排序数组//将数组的键值全部替换成数字0开头的数组
		$params['data'] = json_encode($params['data']);
		$td_name1 = !empty($params['formParams']['td_name1'])?$params['formParams']['td_name1']:'标题';//第1列名称
		$td_width1 = !empty($params['formParams']['td_width1'])?$params['formParams']['td_width1'].'px':'150px';//第1列宽度
		$td_maxlength1 = !empty($params['formParams']['td_maxlength1'])?$params['formParams']['td_maxlength1']:'';//第1列maxlength
		$td_name2 = !empty($params['formParams']['td_name2'])?$params['formParams']['td_name2']:'链接';//第2列名称
		$td_width2 = !empty($params['formParams']['td_width2'])?$params['formParams']['td_width2'].'px':'150px';//第2列宽度
		$td_maxlength2 = !empty($params['formParams']['td_maxlength2'])?$params['formParams']['td_maxlength2']:'';//第2列maxlength
		//限制最大行数
		$max_num = My::arr2var($params,'formParams.max_num');
		//资源文件
		$theme = __PUB__.'share';
		$html= "<!--array_input S-->
				<div class='{$params['class']}'>
				  <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
				  <table class='change_table'>
					<thead>
						<tr class='thead'>
							<th style='width:{$td_width1};'>{$td_name1}</th>
							<th style='width:{$td_width2};'>{$td_name2}</th>
							<th style='width:40px;'><img src='{$theme}/images/gg_icon1.png' max_num='{$max_num}' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				  </table>
				</div>
				<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
				<script>
					$(function(){
						$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
					});
				</script>
				<script id='{$params['class']}_tr_html' type='text/html'>
					<tr lang='<%=num%>'>
					<td class='textal'> <input style='width:{$td_width1};' maxlength='{$td_maxlength1}' type='text' class='{$params['class']}' name='{$params['name']}[<%=num%>][key]' value='<%=result?result['key']:''%>'/> </td>
					<td class='textal'> <input style='width:{$td_width2};' maxlength='{$td_maxlength2}' type='text' name='{$params['name']}[<%=num%>][value]' value='<%=result?result['value']:''%>'/> </td>
					<td class='textac'><img src='{$theme}/images/gg_icon2.png' class='reduce'/></td>
					</tr>
				</script>
				<!--array_input E-->";
		return $html;
	}

	/**
	 * 动态项(文本)
	 * @param string $params.name input框名称
	 * @param serialize $params.data 序列化的值
	 * @param string $params.type $params.type='params'时控件名称为数组形式params[name]
	 * @param string $params.formParams 表单模型的配置参数
	 * @return html
	 */
	public static function input_array($params=''){
		if(My::arr2var($params,'name')=='')  return '控件的name属性不能为空!';
		//解释params参数
		$params = self::dealParams($params);
		//data解码
		if(!is_array($params['data']))
			$params['data'] = My::decodeJson($params['data']);
		//maxlength
		$maxlength = !empty($params['formParams']['maxlength'])?"maxlength='".$params['formParams']['maxlength']."'":'';
		$placeholder = !empty($params['formParams']['placeholder'])?"placeholder='".$params['formParams']['placeholder']."'":'';
		$width = !empty($params['formParams']['width'])?'width:'.$params['formParams']['width'].'px;':'width:215px;';
		$td_name = !empty($params['formParams']['td_name'])?$params['formParams']['td_name']:'值';
		//限制最大行数
		$max_num = My::arr2var($params,'formParams.max_num');
		//json
		$params['data'] = is_array($params['data'])?array_values($params['data']):array();//重新排序数组//将数组的键值全部替换成数字0开头的数组
		$params['data'] = json_encode($params['data']);
		//print_r($data);
		$theme = __PUB__.'share';
		$html= "<!--array_input S-->
				<div class='{$params['class']}'>
				  <span class='label number_stat' style='position:absolute;margin-top:-3px;margin-left:-3px;'></span>
				  <table class='change_table'>
					<thead>
						<tr class='thead'>
							<th style='{$width}'>{$td_name}</th>
							<th style='width:65px;'><img src='{$theme}/images/gg_icon1.png' max_num='{$max_num}' class='add_tr' title='鼠标左击:前, 鼠标右击:后'/></th>
						</tr>
					</thead>
					<tbody>
					</tbody>
		  		  </table>
				</div>
				<script>$(document).ready(function(){ $('.{$params['class']} tbody').sortable({items:\"tr:not('.nodrag')\"}); });</script>
				<script>
					$(function(){
						$('.{$params['class']}').changeTable({data:'{$params['data']}',trHtmlId:'{$params['class']}_tr_html'});
					});
				</script>
				<script id='{$params['class']}_tr_html' type='text/html'>
					<tr lang='<%=num%>'>
						<td class='textal'> <input type='text' lang='<%=num%>' {$maxlength} {$placeholder} style='{$width}' class='input_{$params['class']}' name='{$params['name']}[<%=num%>]' value='<%=result%>'/> </td>
						<td class='textac'> <img src='{$theme}/images/gg_icon2.png' class='reduce'/></td>
					</tr>
				</script>
				<!--array_input E-->";
		return $html;
	}

	/**
	 * Input
	 * @param string name
	 * @param string fullName
	 * @param string value
	 * @return html
	 */
	public static function input($params=''){
		//解释params参数
		$params = self::dealParams($params);
		$maxlength = !empty($params['formParams']['maxlength'])?"maxlength='{$params['formParams']['maxlength']}'":'';//maxlength
		$width = !empty($params['formParams']['width'])?'width:'.$params['formParams']['width'].'px;':'';//宽度
		$placeholder = !empty($params['formParams']['placeholder'])?"placeholder='{$params['formParams']['placeholder']}'":'';//placeholder
		//return
		return "<input class='input-xlarge' style='{$width}' {$maxlength} {$placeholder} name='{$params['name']}' type='text' value='{$params['data']}'/>";
	}

	/**
	 * 处理参数
	 * @param string name
	 * @param string fullName
	 * @param string $params.is_params 是否要在控件名加上params[]
	 * @param string class
	 * @param string formParams
	 * @param string data
	 */
	private static function dealParams($params=''){
		//得到name//有全名时取全名, 否则没全名时 (默认是params前缀的参数,除非参数为指定fullName)
		if(!empty($params['fullName'])){
			$result['name'] = $params['fullName'];
			unset($params['fullName']);
		}elseif(isset($params['is_params']) AND $params['is_params']==true){
			$result['name'] = "params[{$params['name']}]";
			unset($params['is_params']);
		}elseif(isset($params['name']))
			$result['name'] = $params['name'];
		else
			$result['name'] = '';
		//标签的class
		$result['class'] = !empty($params['class'])?$params['class']:(!empty($result['name'])?$result['name']:'');
		$result['class'] = str_replace(array('[',']'),'_',$result['class']);//将[和]替换成_,防止选择器冲突
		//得到formParams
		if(isset($params['id']) AND My::is_id($params['id'])){//有id值时<{{form id=xxx}}>, 直接取form表中id中的params字段作为formParams
			$result['formParams'] = My::id2field('form',$params['id'],'params');
		}else{
			$result['formParams'] = !empty($params['formParams'])?My::decodeJson($params['formParams']):'';
		}
		//得到控件的值:data
		$result['data'] = isset($params['data'])?$params['data']:'';
		//补充一些上面没有作处理的其它参数
		if(is_array($params))
		foreach($params as $key=>$value){
			if(empty($result[$key]))
				$result[$key] = $value;
		}
		return $result;
	}
	

}